package com.wawei.seeds.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wawei.seeds.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by parker on 15/6/14.
 */
public class ChampionAchievementFragmentAdapter extends BaseAdapter {
    private Context context;
    private List<ChampionAchievementItem> dataset = new ArrayList<>(0);

    public ChampionAchievementFragmentAdapter(Context context) {
        this.context = context;
    }

    public void setDataset(List<ChampionAchievementItem> dataset) {
        this.dataset = dataset;
    }

    public void appendDataset(List<ChampionAchievementItem> append){
        this.dataset.addAll(append);
    }

    public void insertDataset(List<ChampionAchievementItem> insert){
        for(ChampionAchievementItem item : insert){
            this.dataset.add(0, item);
        }
    }

    @Override
    public int getCount() {
        return dataset.size();
    }

    @Override
    public Object getItem(int position) {
        return dataset.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder viewHolder;
        if(null == convertView){
            view = LayoutInflater.from(context).inflate(R.layout.fragment_champion_achievement_item, parent, false);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        }
        else{
            view = convertView;
            viewHolder = (ViewHolder)view.getTag();
        }
        viewHolder.achievementTitleView.setText(dataset.get(position).achievementTitle);
        viewHolder.achievementPublishTimeView.setText(dataset.get(position).achievementPublishTime);
        viewHolder.achievementWorksView.setText(dataset.get(position).achievementWorkers);

        return view;
    }

    public static class ChampionAchievementItem {
        public String achievementTitle;
        public String achievementPublishTime;
        public String achievementWorkers;
    }

    public static class ViewHolder{
        private View view;

        @InjectView(R.id.achieveTitle)TextView achievementTitleView;
        @InjectView(R.id.achievePublishTime)TextView achievementPublishTimeView;
        @InjectView(R.id.achieveWorkers)TextView achievementWorksView;

        public ViewHolder(View view) {
            this.view = view;
            ButterKnife.inject(this, view);
        }
    }
}
